import { post } from '../http'
import { domainid } from '@/utils/cloud/utils'

// 获取配置
export function getConfigApi(data) {
  let params = {
    application: 'config',
    datasource: 'config_service',
    name: 'all',
    param: {
      ...data,
      domain_id: data.domain_id || domainid(true)
    }
  }
  return post(`/datapool/mysql`, params)
}

// 保存配置
export function updateConfigApi(data, reqdata) {
  const { app_application, app_datasource, app_name, ...attrs } = data || {}
  let params = reqdata || {
    [app_application]: {
      [app_datasource]: {
        [app_name]: attrs
      }
    }
  }
  return post(`/datapool/query_config/import`, params)
}

// 删除配置
export function deleteConfigApi(data) {
  return post(`/datapool/mysql/${domainid()}/config_service/sql_config`, data)
}

// 上传图片
export function uploadPicture(data) {
  return post(`/oss/upload/picture`, data, 'multipart/form-data;charset=UTF-8')
}

// 登录
export function loginApi(data) {
  return post(`/auth/login`, data)
}

// 发布到网关
export function uploadDataToGatawayApi(data, headers) {
  return post(`${import.meta.env.VITE_UPLOAD_URL}/view/upload`, data, null, headers)
}
